<%
layout("/layouts/platform.html"){
%>
<%DIRECTIVE DYNAMIC;%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-default navbar-btn" href="${base}/platform/trainer" data-pjax><i class="ti-angle-left" id="goback"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="companyAddForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/trainer/editDo" method="post">
                <input type="hidden" name="id" value="${obj.trainer.id!}"/>
                <input type="hidden" name="createAt" value="${obj.trainer.createAt!}"/>
                <div class="row mb10">
                    <div class="col-lg-12">
                    	<div class="form-group">
                            <label for="card_type" class="col-sm-2 control-label">选择驾校</label>
                            
                            <div class="col-sm-8">
                                <select id="school_id" name="school_id" class="form-control" >
                                	<option value="">--选择驾校--</option>
                                	<%for(school in obj.schoolList){%>
                                		 <option value="${school.id}" <% if(obj.trainer.school_id ==school.id){%>selected="selected"<%}%> >${school.name}</option>
                                	<%}%>
                                </select>
                            </div>
                        </div>
                    	<div class="form-group">
                        	<label for="headimg" class="col-sm-2 control-label">头像</label>

                            <div class="col-sm-8">
                            	<div id="headimg_queue"></div>
                                <div>
                                	<input id="headimg_file_upload"  type="file" multiple="false">
                                </div>
                                <div id="headimg_img" style="padding: 5px;">
                                	<%if(!isEmpty(obj.trainer.headimg)){%>
                                        <img src='${AppUploadRoot}${obj.trainer.headimg!}' style='width:150px;'>
                                        <i class="fa fa-close" onclick="$('#headimg').val('');$('#headimg_img').html('');"></i>
                                   <%}%>
                                </div>
                                <input type="hidden" id="headimg" name="headimg" value="${obj.trainer.headimg!}" >
                           	</div>
                       	</div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">名称</label>

                            <div class="col-sm-8">
                                <input type="text" id="name" value="${obj.trainer.name!}" class="form-control" name="name" data-parsley-required="true" placeholder="名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="mobile" class="col-sm-2 control-label">电话</label>

                            <div class="col-sm-8">
                                <input type="text" id="mobile"  value="${obj.trainer.mobile!}" class="form-control" name="mobile"  placeholder="电话" data-parsley-required="true" data-parsley-type="number">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sex" class="col-sm-2 control-label">性别</label>

                            <div class="col-sm-8">
                                 <input type="radio" name="sex" data-parsley-required="true" value="0" <% if(obj.trainer.sex =='0'){%>checked="checked"<%}%> />男
                                 <input type="radio" name="sex" data-parsley-required="true" value="1" <% if(obj.trainer.sex =='1'){%>checked="checked"<%}%> />女
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="id_no" class="col-sm-2 control-label">身份证</label>

                            <div class="col-sm-8">
                                <input type="text" id="id_no" value="${obj.trainer.id_no!}"  class="form-control" name="id_no"  placeholder="身份证" data-parsley-required="true">
                            </div>
                        </div>
                        <div class="form-group" >
	                 		<label for="birth" class="col-sm-2 control-label">出生日期</label>
	                           	
	                   		<div class="col-sm-3">
	                      		<input type="text" size="16"  class="form-control" value="${@date.getDateString(obj.trainer.birth!)}" data-parsley-required="true" id="birth" name="birth">
	                		</div>
	                    </div>
	                    <div class="form-group">
                            <label for="projects" class="col-sm-2 control-label">选择项目</label>
                            
                            <div class="col-sm-8">
                                <%for(project in obj.projects){%>
                                	<input type="checkbox" name="projects" data-parsley-required="true" value="${project.id}" <%for(trainerProject in obj.trainerProjects){ if(trainerProject.project_id==project.id){%> checked="checked"  <%}}%>/>${project.name}
                                <%}%>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="state" class="col-sm-2 control-label">状态</label>

                            <div class="col-sm-8">
                                 <input type="radio" name="state" data-parsley-required="true" value="0"  <% if(obj.trainer.state ==0){%>checked="checked"<%}%> />启用
                                 <input type="radio" name="state" data-parsley-required="true" value="1"  <% if(obj.trainer.state ==1){%>checked="checked"<%}%> />禁用
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="memo" class="col-sm-2 control-label">备注</label>

                            <div class="col-sm-8">
                                <textarea rows="5" cols="5" id="memo"   class="form-control" name="memo" data-parsley-required="true" data-parsley-maxlength="5000"  placeholder="备注">${obj.trainer.memo!}</textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<a class="exit-offscreen"></a>
<script language="JavaScript">

	function headimg_clearFile() {
	    $("#headimg_img").html("");
	    $("#headimg_queue").html("");
	    $("#headimg").val("");
	}
    $(document).ready(function () {
    	$.datetimepicker.setLocale('ch');
      	$('#birth').datetimepicker({
     		lang:'ch',
       		timepicker:false,
       		format:'Y-m-d',
       		formatDate:'Y-m-d'
     	});
    	$('#headimg_file_upload').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '请选择图片',
            'fileType': 'image/*',
            'fileSizeLimit': 1024,
            'queueSizeLimit': 1,
            'formData': {},
            'queueID': 'headimg_queue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#headimg_img").html("<img src='${AppUploadRoot}" + data.data + "' style='width:150px;height:95px;'>");
                    $("#headimg").val(data.data);
                } else {
                	headimg_clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
            	headimg_clearFile();
            },
            'onClearQueue': function (queue) {
            	headimg_clearFile();
            },
            'onCancel': function () {
            	headimg_clearFile();
            }
        });
        $('#companyAddForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
            }
        });
    });
</script>
<%}%>